package com.lottery.game.controller.v2.websocket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;

import com.lottery.game.core.model.websocket.InboundCustomerMessage;
import com.lottery.game.core.model.websocket.InboundCustomerServiceSystemMessage;
import com.lottery.game.core.model.websocket.InboundRoomMessage;
import com.lottery.game.core.modules.service.app.WebSocketService;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Controller
public class WebSocketController {
	
	@Autowired
	private WebSocketService webSocketService;
	
	/**
	 * 推送在线人数
	 */
	@Scheduled(fixedRate = 10000)
	public void onlineUser() {
		webSocketService.sendOnlineUser();
	}
	
	/**
	 * user->cs
	 * @param message
	 * @throws Exception
	 */
	@MessageMapping(value="/send/cs")
	public void sendSpecialUser(InboundCustomerMessage message) throws Exception {
		log.info("----sendSpecialUser----");
		webSocketService.sendToTheUser(message);
	}
	
	/**
	 * cs->user
	 * @param message
	 * @throws Exception
	 */
	@MessageMapping(value="/send/cs/system")
	public void sendSystemCustomerServiceMessage(InboundCustomerServiceSystemMessage message) throws Exception {
		log.info("----sendSystemCustomerServiceMessage----");
		webSocketService.sendToTheUser(message);
	}
	
	@MessageMapping(value="/send/room")
	public void sendRoomMessage(InboundRoomMessage message) throws Exception {
		webSocketService.sendRoomMessage(message);
	}
	
	@MessageMapping(value="/bet")
	public void bet(InboundRoomMessage message) throws Exception {
		webSocketService.sendRoomMessage(message);
	}
	
//	@Scheduled(fixedRate = 5000)
//	public void test() {
//		log.info("   ----每5秒发送一次-----");
//		webSocketService.sendToTheUser("test", "5afec15783e7490ca6eae7a9012892dc", "");
//	}
	
}
